﻿namespace CSharpPro._10_16;

public class Demo
{
    public void Test1()
    {
        Console.WriteLine("请输入三个整数，用空格分隔：");
        string[] nums = Console.ReadLine().Split();
        int x = int.Parse(nums[0]);
        int y = int.Parse(nums[1]);
        int z = int.Parse(nums[2]);

        int temp;
        
        if (x > y)
        {
            temp = x;
            x = y;
            y = temp;
        }

        if (x > z)
        {
            temp = x;
            x = z;
            z = temp;
        }

        if (y > z)
        {
            temp = y;
            y = z;
            z = temp;
        }

        Console.WriteLine($"从小到大排序：{x} {y} {z}");
    }

    public void Test2()
    {
        int sum = 0;
        Console.WriteLine("符合条件的数字：");
        for (int i = 1; i <= 100; i++)
        {
            if (i % 7 != 0 && !i.ToString().Contains("7"))
            {
                Console.Write(i + " ");
                sum += i;
            }
        }

        Console.WriteLine($"\n这些数字的和为：{sum}");
    }

    public void Test3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j}×{i}={i * j}\t");
            }

            Console.WriteLine();
        }

    }

    public void Test4()
    {
        Console.WriteLine("1000以内的完数：");
        for (int i = 2; i <= 1000; i++)
        {
            int factorSum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    factorSum += j;
                }
            }

            if (factorSum == i)
            {
                Console.Write(i + " ");
            }
        }

        Console.WriteLine();

    }

    public void Test5()
    {
        Console.Write("请输入一个正整数：");
        int num = int.Parse(Console.ReadLine());
        int n = num;
        int i = 0;
        string reversed = "";

        while (num > 0)
        {
            reversed += num % 10;
            num /= 10;
            i++;
        }

        Console.WriteLine($"{n}是{i}位数");
        Console.WriteLine($"逆序打印：{reversed}");
    }


    public void Test6()
    {
        Console.WriteLine("请输入菱形的行数（奇数）：");
        int rows = int.Parse(Console.ReadLine());
        int half = rows / 2;

        // 上半部分（包括中间行）
        for (int i = 0; i <= half; i++)
        {
       
            for (int j = 0; j < half - i; j++)
            {
                Console.Write(" ");
            }

            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }
            Console.Write("\n");

        }

        // 下半部分
        for (int i = half - 1; i >= 0; i--)
        {
            for (int j = 0; j < half - i; j++)
            {
                Console.Write(" ");
            }

            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }
            Console.Write("\n");

        }

    }
}

